import os
import glob

def read_text_files_in_directory(directory):
    # 检查目录是否存在
    if not os.path.exists(directory):
        print(f"目录 '{directory}' 不存在")
        return []

    # 获取目录下所有的文本文件
    text_files = glob.glob(os.path.join(directory, '*.txt'))

    # 逐个读取文本文件的内容
    file_contents = []
    for file_path in text_files:
        with open(file_path, 'r') as file:
            content = file.read()
            file_contents.append((file_path, content))

    return file_contents

# 示例用法
directory_path = 'D:/cococo/labels/train2024'  # 修改为你的目录路径
files_content = read_text_files_in_directory(directory_path)

# 打印每个文件的内容
for file_path, content in files_content:
    if(str(62 ) in content):
        print(f"文件 '{file_path}' 的内容：")
        print(content)
        print()